package vip.xiaonuo.invoice.core.common;



import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;


/**
 * Description: 通用返回体
 */
@Data
@Schema(description = "状态码")
public class ApiResult<T> {
    @Schema(description = "状态码")
    private Boolean success;
    @Schema(description = "状态码")
    private Integer errCode;
    @Schema(description = "状态码")
    private String errMsg;
    @Schema(description = "状态码")
    private T data;

    public static <T> ApiResult<T> success() {
        ApiResult<T> result = new ApiResult<T>();
        result.setData(null);
        result.setSuccess(Boolean.TRUE);
        return result;
    }

    public static <T> ApiResult<T> success(T data) {
        ApiResult<T> result = new ApiResult<T>();
        result.setData(data);
        result.setSuccess(Boolean.TRUE);
        return result;
    }


    public static <T> ApiResult<T> fail(Integer code, String msg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(Boolean.FALSE);
        result.setErrCode(code);
        result.setErrMsg(msg);
        return result;
    }

//   public static <T> ApiResult<T> fail(BasicEnum basicEnum) {
//       ApiResult<T> result = new ApiResult<T>();
//       result.setSuccess(Boolean.FALSE);
//       result.setErrCode(basicEnum.getCode());
//       result.setErrMsg(basicEnum.getMsg());
//       return result;
//   }

    public boolean isSuccess() {
        return this.success;
    }
}
